﻿using System.Collections.Generic;
using Kam.Lagan.Examples.Atm.Console.Runner.Ioc;
using Kam.Lagan.Examples.Atm.Contract;
using Kam.Lagan.Examples.Atm.Contract.Bll;
using Kam.Lagan.Examples.Atm.Contract.Model;
using Kam.Lagan.Examples.Atm.Model;
using Ninject;

namespace Kam.Lagan.Examples.Atm.Console.Runner
{
    class Program
    {
        static void Main()
        {
            var kernel = new StandardKernel(new LiveBinding());

            var accountRepository = kernel.Get<IAccountBll>();
            var transactionFactory = kernel.Get<ITransactionFactory>();

            var accounts = accountRepository.Get();

            var a = accounts[0];
            a.Transact(transactionFactory.Debit(12.99));
            a.Transact(transactionFactory.Debit(2.99));
            a.Transact(transactionFactory.Credit(1223.99));
            a.Transact(transactionFactory.Debit(156.99));
            a.Transact(transactionFactory.Debit(2.90));

            a = accounts[4];
            a.Transact(transactionFactory.Credit(23.99));
            a.Transact(transactionFactory.Debit(16.99));
            
            PrintAccounts(accounts);

            System.Console.WriteLine("\nComplete - Press <Return>");
            System.Console.ReadLine();
        }

        static void PrintAccounts(IEnumerable<ICurrentAccount> accounts)
        {
            foreach (var a in accounts)
            {
                System.Console.WriteLine("{0} {1} => {2} / {3}\nTransactions\n---------------", a.Client.FirstName, a.Client.LastName, a.Number, a.SortCode);
                foreach (var t in a.Transactions)
                {
                    System.Console.WriteLine("{0}: {1} => {2} => {3}", t is Debit ? "DEBIT" : "CREDIT",  t.Id, t.Date, t.Amount);
                }
                System.Console.WriteLine("\n");
            }
        }
    }
}
